﻿@model PagedUser_XsModel
@{
    ViewBag.Title = "权限管理";
    Layout = "~/Views/Shared/_LayoutAdmin.cshtml";
}
<div class="right_title2">
    <a href="/Navigate/Index">首页</a> ><span>配置用户</span></div>
<div class="index_lr">
    <ul>
        <li class="index_lr2_M">
            <div class="index_lrA_title ui-icons">
                <h3>
                    用户列表</h3>
            </div>
            <div class="index_pt_bg">
                <div class="search_bg">
                    <label>
                        登录名：</label>
                    <input id="Check_UserName" type="text" />
                    <label>
                        姓名：</label>
                    <input id="Check_UserDisplayName" type="text" />
                    <input type="button" id="check" value="查询" onclick="check();" />
                </div>
                <br />
                <div id="gridUser_X_Index">
                    @{
                        var grid = new WebGrid(null, rowsPerPage: Model.PageSize,
                             ajaxUpdateContainerId: "gridUser_X_Index", canPage: true, canSort: true, ajaxUpdateCallback: "initgridUser_X_Index");
                        grid.Bind(Model.User_Xs, new[] { "ID", "DisplayName", "Name", "Company", "Department", "Position", "IsAdmin" }, autoSortAndPage: false, rowCount: int.Parse(Model.TotalRows + ""));
                    }
                    @grid.GetHtml(tableStyle: "ContactTB talbe_gray", headerStyle: "ContactTH", htmlAttributes: new { width = "100%", border = 0, cellpadding = 0, cellspacing = 0 },
                    columns: grid.Columns(grid.Column("ID", "标识符", style: "Hiden"),
                    grid.Column("DisplayName", "姓名", style: "ContactTD"),
                    grid.Column("Name", "登录名", style: "ContactTD"),
                    grid.Column("Company", "公司", style: "ContactTD"),
                    grid.Column("Department", "部门", style: "ContactTD"),
                    grid.Column("Position", "职务", style: "ContactTD"),
                    grid.Column("IsAdmin", "配置管理员", style: "ContactTD", format: @<text><input type="checkbox" disabled="disabled" @if ((item.IsAdmin ?? 0) != 0)
                                                                                                                                  { <text> checked="checked" </text> }/></text>)))
                </div>
            </div>
        </li>
    </ul>
</div>
<input type="hidden" id="UserID" />
<input type="hidden" id="login" />
<div class="clear">
</div>
<div id="userInfo" data-url="">
</div>
<div id="userEdit" title="编辑用户权限">
</div>
<div id="userChangePassWord" title="更改用户密码">
</div>
@section LeftMenu{
    <li><a href="@Url.Action("CreateUser", "AdminPermission")">创建用户</a></li>
    <li class="VNavLeaf ui-icons">配置用户</li>
    <li><a href="@Url.Action("Add", "AdminBS")">添加业务系统</a></li>
    <li><a href="@Url.Action("Index", "AdminBSMaintain")">维护业务系统</a></li>
    <li><a href="@Url.Action("Admin", "AdminDocument")">常用资源管理</a></li>
    <li><a href="@Url.Action("Index", "AdminOther")">其他管理</a></li>
}
@section ScriptAndCss{
    @*    <script src="../../Scripts/jquery-1.4.4-vsdoc.js" type="text/javascript"></script>*@
    <script type="text/javascript">
        function initgridUser_X_Index() {
            $("tr", $("thead", "#gridUser_X_Index")).children().first().hide();
            $("tr", $("tbody", "#gridUser_X_Index")).click(function () {
                $(this).siblings().css("background-color", "white");
                $(this).css("background-color", "#ccc");
                var id=$(this).children().first().text();
                var login=$($(this).children()[2]).text();
                var url="@Url.Action("UserInfo", "AdminPermission")";
                url+="?userID="+id;
                $("#UserID").val(id);
                $("#login").val(login);
                $("#userInfo").load(url);
                $("#userInfo").attr("data-url",url);
            });
        }
        $(document).ready(function () {
            initgridUser_X_Index();
            $("#userEdit").dialog({
            autoOpen: false, width: 560, height: 420, modal: true,
            buttons: {
                "保存": function () {
                    $.post("@Url.Action("UserEdit", "AdminPermission")",
                        $("#userEditorForm").serialize(),
                        function (data) {
                        if(data!="")
                        {
                        alert(data);
                        }
                        else
                        {

                            $("#userEdit").dialog("close");
                             $("#userInfo").load($("#userInfo").attr("data-url"));
                             }
                        });
                },
                "取消": function () { $(this).dialog("close"); }
            }
        });

       $("#userChangePassWord").dialog({
            autoOpen: false, width: 560, height: 420, modal: true,
            buttons: {
                "保存": function () {
                   if($("#mpassword").val()==$("#cmpassword").val())
                   {
                    $.post("@Url.Action("ChangePassword", "AdminPermission")",
                        "login="+$("#login").val()+"&pass="+$("#mpassword").val(),
                        function () {
                            $("#userChangePassWord").dialog("close");
                        });
                        }
                        else
                        {
                        alert("两次密码输入不一致，请重新输入");
                        }
                },
                "取消": function () { $(this).dialog("close"); }
            }
        });
        });

        function check()
        {
//             $.ajax({
//                type: "GET",
//                url: "@Url.Action("Index", "AdminPermission")",
//                data: { "name": $("input#Check_UserName").val(),
//                        "displayname": $("input#Check_UserDisplayName").val()
//                },
//                success: function (result) {
//                    $("#permissionview").empty();
//                    $("#permissionview").append(result);
//                    
//                }
//            });
            window.location.href="/AdminPermission/Index?name="+ $("input#Check_UserName").val()+"&&displayname="+ $("input#Check_UserDisplayName").val();

        }

        function editUserDialog()
        {
          var url="@Url.Action("UserEdit", "AdminPermission")";
                url+="?userID="+$("#UserID").val();
          $("#userEdit").load(url,function()
          {
          initTheEditUserDialog();
          });
          $("#userEdit").dialog( "open" );
        }

        function editPassWordDialog()
        {
          var url="@Url.Action("ChangePassword", "AdminPermission")";
          $("#userChangePassWord").load(url,function()
          {
          //initTheEditUserDialog();
          });
          $("#userChangePassWord").dialog( "open" );
        }
        


        function initTheEditUserDialog()
        {
//          $("#selectALLSite").change(function()
//          {
//          if($(this).is(":checked"))
//          {
//          $(this).nextAll(":checkbox").attr("checked",true);
//          }
//          else
//          {
//           $(this).nextAll(":checkbox").attr("checked",false);
//          } 
//          });
//          $("#selectALLSite2").change(function()
//          {
//          if($(this).is(":checked"))
//          {
//          $(this).nextAll(":checkbox").attr("checked",true);
//          }
//          else
//          {
//           $(this).nextAll(":checkbox").attr("checked",false);
//          } 
//          });
//          $("#cleanALLSite").click(function(){
//           $(this).nextAll(":checkbox").attr("checked",false).removeAttr("readonly");
//           $("#selectALLSite").attr("checked",false);
//          });
        }

    </script>
}
